﻿<Window x:Class="XDraw.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:avalonDock="http://avalondock.codeplex.com"
        xmlns:xdEditor="clr-namespace:XDraw.Editor;assembly=XDraw.Editor"
        xmlns:xdCore="clr-namespace:XDraw;assembly=XDraw2.Core"
        xmlns:local="clr-namespace:XDraw"
        Title="XDraw 2" Height="600" Width="800"
        Background="{StaticResource ToolBarTrayBackground}"
        Activated="Window_Activated"
        Loaded="Window_Loaded">

  <Window.Resources>
    <local:ActiveDocumentConverter x:Key="ActiveDocumentConverter"/>
    <avalonDock:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
  </Window.Resources>

  <Window.CommandBindings>
    <CommandBinding Command="New" Executed="New_Executed"/>
    <CommandBinding Command="Open" Executed="Open_Executed"/>
  </Window.CommandBindings>
  
  <DockPanel DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}, Path=.}">
    <DockPanel DockPanel.Dock="Top">
      <DockPanel DockPanel.Dock="Right">
        <Image Source="{StaticResource XDrawImage}" VerticalAlignment="Center" Margin="2" MaxWidth="50"/>
      </DockPanel>
      
      <Menu DockPanel.Dock="Top" xdCore:MergeMenus.Id="MainMenu">
        <MenuItem Header="File"
                  xdCore:MergeMenus.Id="FileMenu" xdCore:MergeMenus.Priority="0">
          <MenuItem Header="New" Command="New" CommandTarget="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}, Path=.}"
                    xdCore:MergeMenus.Priority="0"/>
          <MenuItem Header="Open" Command="Open" CommandTarget="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}, Path=.}"
                    xdCore:MergeMenus.Priority="0"/>
          <MenuItem Header="Save" Command="Save"
                    xdCore:MergeMenus.Priority="0"/>
          
          <Separator xdCore:MergeMenus.Priority="1000"/>
          <MenuItem Header="Exit" Click="Exit_Click"
                    xdCore:MergeMenus.Priority="1000"/>
        </MenuItem>

        <MenuItem Header="_Edit"
                  xdCore:MergeMenus.Id="EditMenu" xdCore:MergeMenus.Priority="200">
          <MenuItem Header="_Undo"
                    xdCore:MergeMenus.Priority="10"
                    Command="Undo"/>
          <MenuItem Header="_Redo"
                    xdCore:MergeMenus.Priority="10"
                    Command="Redo"/>

          <Separator xdCore:MergeMenus.Priority="20"/>
          <MenuItem Header="Cu_t"
                    xdCore:MergeMenus.Priority="20"
                    Command="Cut"/>
          <MenuItem Header="_Copy"
                    xdCore:MergeMenus.Priority="20"
                    Command="Copy"/>
          <MenuItem Header="_Paste"
                    xdCore:MergeMenus.Priority="20"
                    Command="Paste"/>
          <MenuItem Header="_Delete"
                    xdCore:MergeMenus.Priority="20"
                    Command="Delete"/>
        </MenuItem>

        <MenuItem Header="_View"
                  xdCore:MergeMenus.Id="ViewMenu" xdCore:MergeMenus.Priority="300">

        </MenuItem>
        <MenuItem Header="_Help"
                  xdCore:MergeMenus.Id="HelpMenu" xdCore:MergeMenus.Priority="10000">
          
        </MenuItem>
      </Menu>

      <ToolBarTray DockPanel.Dock="Top" xdCore:MergeMenus.Id="ToolBarTray">
        <ToolBar Band="0"
                 xdCore:MergeMenus.Id="FileToolBar">
          <Button Command="Open" CommandTarget="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}, Path=.}"
                  xdCore:MergeMenus.Priority="0"
                  ToolTip="Open an existing file">
            <Image Source="{StaticResource LoadDrawingImage}" Style="{StaticResource ToolBarButtonImageStyle}"/>
          </Button>

          <Button Command="Save"
                  xdCore:MergeMenus.Priority="0"
                  ToolTip="Save the current file">
            <Image Source="{StaticResource SaveDrawingImage}" Style="{StaticResource ToolBarButtonImageStyle}"/>
          </Button>

          <Separator xdCore:MergeMenus.Priority="10"/>
          <Button Command="New" CommandTarget="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}, Path=.}"
                  xdCore:MergeMenus.Priority="10"
                  ToolTip="Create a new file">
            <Image Source="{StaticResource NewDrawingImage}" Style="{StaticResource ToolBarButtonImageStyle}"/>
          </Button>
        </ToolBar>

        <ToolBar Band="0"
                 xdCore:MergeMenus.Id="EditToolBar">
          <Button xdCore:MergeMenus.Priority="10"
                  Command="Cut">
            <Image Source="{StaticResource CutImage}" Style="{StaticResource ToolBarButtonImageStyle}"/>
          </Button>
          <Button xdCore:MergeMenus.Priority="10"
                  Command="Copy">
            <Image Source="{StaticResource CopyImage}" Style="{StaticResource ToolBarButtonImageStyle}"/>
          </Button>
          <Button xdCore:MergeMenus.Priority="10"
                  Command="Paste">
            <Image Source="{StaticResource PasteImage}" Style="{StaticResource ToolBarButtonImageStyle}"/>
          </Button>
          <Button xdCore:MergeMenus.Priority="10"
                  Command="Delete">
            <Image Source="{StaticResource DeleteShapeImage}" Style="{StaticResource ToolBarButtonImageStyle}"/>
          </Button>

          <Separator xdCore:MergeMenus.Priority="20"/>
          <Button xdCore:MergeMenus.Priority="20"
                  Command="Undo">
            U
            <!--Image Source="{StaticResource UndoImage}" Style="{StaticResource ToolBarButtonImageStyle}"/-->
          </Button>
          <Button xdCore:MergeMenus.Priority="20"
                  Command="Redo">
            R
            <!--Image Source="{StaticResource RedoImage}" Style="{StaticResource ToolBarButtonImageStyle}"/-->
          </Button>
        </ToolBar>
        
        <ToolBar Band="0"
                 xdCore:MergeMenus.Id="ZoomToolBar">
          <Button xdCore:MergeMenus.Priority="10"
                  Command="{x:Static xdEditor:XDrawEditorCommands.ZoomInCommand}">
            <Image Source="{StaticResource ZoomInImage}" Style="{StaticResource ToolBarButtonImageStyle}"/>
          </Button>
          <Button xdCore:MergeMenus.Priority="10"
                  Command="{x:Static xdEditor:XDrawEditorCommands.ZoomOutCommand}">
            <Image Source="{StaticResource ZoomOutImage}" Style="{StaticResource ToolBarButtonImageStyle}"/>
          </Button>
          <Separator/>
          <Button xdCore:MergeMenus.Priority="10"
                  Command="{x:Static xdEditor:XDrawEditorCommands.ZoomFitCommand}">
            <Image Source="{StaticResource ZoomFitImage}" Style="{StaticResource ToolBarButtonImageStyle}"/>
          </Button>
          <Button xdCore:MergeMenus.Priority="10"
                  Command="{x:Static xdEditor:XDrawEditorCommands.Zoom1Command}">
            <Image Source="{StaticResource Zoom1Image}" Style="{StaticResource ToolBarButtonImageStyle}"/>
          </Button>

        </ToolBar>
      </ToolBarTray>
    </DockPanel>

    <avalonDock:DockingManager x:Name="_DockManager" x:FieldModifier="private"
                               DocumentClosing="DockManager_DocumentClosing"
                               DocumentClosed="DockManager_DocumentClosed"
                               DocumentsSource="{Binding Path=Documents}"
                               AnchorablesSource="{Binding Path=ToolPanes}"
                               ActiveContent="{Binding Path=ActiveDocument, Mode=TwoWay, Converter={StaticResource ActiveDocumentConverter}}">
      <avalonDock:DockingManager.Theme>
        <avalonDock:VS2010Theme/>
      </avalonDock:DockingManager.Theme>

      <avalonDock:DockingManager.LayoutItemTemplateSelector>
        <local:PanesTemplateSelector>
          <local:PanesTemplateSelector.DocumentTemplate>
            <DataTemplate>
              <ContentPresenter Content="{Binding Path=DocumentContent}"/>
            </DataTemplate>
          </local:PanesTemplateSelector.DocumentTemplate>
          <local:PanesTemplateSelector.PaneTemplate>
            <DataTemplate>
              <ContentPresenter Content="{Binding Path=PaneContent}"/>
            </DataTemplate>
          </local:PanesTemplateSelector.PaneTemplate>
        </local:PanesTemplateSelector>
      </avalonDock:DockingManager.LayoutItemTemplateSelector>

      <avalonDock:DockingManager.LayoutItemContainerStyleSelector>
        <local:PanesStyleSelector>
          <local:PanesStyleSelector.DocumentStyle>
            <Style TargetType="{x:Type avalonDock:LayoutItem}">
              <Setter Property="Title" Value="{Binding Path=Model.DocumentTitle}"/>
              <Setter Property="ToolTip" Value="{Binding Path=Model.DocumentToolTip}"/>
              <!--Setter Property="IconSource" Value="{Binding Path=Model.DocumentIconSource}"/-->
              <Setter Property="ContentId" Value="{Binding Path=Model.DocumentId}"/>
            </Style>
          </local:PanesStyleSelector.DocumentStyle>

          <local:PanesStyleSelector.PaneStyle>
            <Style TargetType="{x:Type avalonDock:LayoutItem}">
              <Setter Property="Title" Value="{Binding Path=Model.PaneTitle}"/>
              <Setter Property="ToolTip" Value="{Binding Path=Model.PaneToolTip}"/>
              <!--Setter Property="IconSource" Value="{Binding Path=Model.PaneIconSource}"/-->
              <Setter Property="Visibility" Value="{Binding Path=Model.IsPaneVisible, Mode=TwoWay, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter={x:Static Visibility.Hidden}}"/>
              <Setter Property="ContentId" Value="{Binding Path=Model.PaneId}"/>
            </Style>
          </local:PanesStyleSelector.PaneStyle>
        </local:PanesStyleSelector>
      </avalonDock:DockingManager.LayoutItemContainerStyleSelector>

      <avalonDock:DockingManager.DocumentHeaderTemplate>
        <DataTemplate DataType="{x:Type avalonDock:LayoutDocument}">
          <DockPanel>
            <Image DockPanel.Dock="Left" Margin="3,0,0,0" VerticalAlignment="Center" Width="16" Height="16"
                   Source="{Binding Path=Content.DocumentIcon}"
                   Visibility="{Binding Path=Content.DocumentIcon, Converter={x:Static xdCore:ValueConverters.ObjectNotNullVisibity}}"/>
            
            <TextBlock DockPanel.Dock="Right" Text="l" Margin="5,0,0,0"
                       Visibility="{Binding Path=Content.IsDocumentLocked, Converter={StaticResource BoolToVisibilityConverter}}"/>
            <Ellipse DockPanel.Dock="Right" Margin="3,0,0,0"
                     Width="6" Height="6" VerticalAlignment="Center"
                     Stroke="Black" Fill="Red"
                     Visibility="{Binding Path=Content.IsDocumentModified, Converter={StaticResource BoolToVisibilityConverter}}"/>

            <TextBlock Text="{Binding Path=Title}" Margin="3,0,0,0" VerticalAlignment="Center"/>
          </DockPanel>
        </DataTemplate>
      </avalonDock:DockingManager.DocumentHeaderTemplate>
      
      <avalonDock:LayoutRoot>
        <avalonDock:LayoutPanel>
          <!--avalonDock:LayoutAnchorablePane DockWidth="200"/-->
          <avalonDock:LayoutDocumentPane/>
          <avalonDock:LayoutAnchorablePane DockWidth="250"/>
        </avalonDock:LayoutPanel>
      </avalonDock:LayoutRoot>
    </avalonDock:DockingManager>

  </DockPanel>
</Window>
